﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Miris.HumanMilkAnalyser.WPF.Shared
{
    public class UserControlBase : System.Windows.Controls.UserControl
    {
        public UserControlBase()
        {
            RegisterMessages();

            Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
            Unloaded += UserControlBase_Unloaded;
        }

        /// <summary>
        /// Register all necessary messages.
        /// </summary>
        protected virtual void RegisterMessages() { }

        /// <summary>
        /// Perform clean up for view & view model
        /// </summary>
        protected virtual void Cleanup()
        {
            ViewHelper.Cleanup(this);
        }

        protected virtual void Dispatcher_ShutdownStarted(object sender, EventArgs e)
        {
            Cleanup();
        }

        protected virtual void UserControlBase_Unloaded(object sender, RoutedEventArgs e)
        {
            Cleanup();
        }
    }
}
